package com.infinitegroup.findmystuff.activities;

import com.infinitegroup.findmystuff.R;
import com.infinitegroup.findmystuff.presenters.LockoutPresenter;
import com.infinitegroup.findmystuff.views.LockoutView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Handles the inputs of the lock out screen and gives these inputs to the lock out
 * controller and can advance to the login screen.
 * 
 * @author Maria
 *
 */
public class LockoutActivity extends Activity implements LockoutView{
	
	private LockoutPresenter presenter;

	/**
	 * Handles the start of the activity and sets the listeners for the buttons on the screen.
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lockout);
		
		presenter = new LockoutPresenter(this);
		
		Button send = (Button) findViewById(R.id.send_request);
		send.setOnClickListener(new onSendClick());
		
	}
	
	/**
	 * Creatres a button listener for the send request button.
	 * 
	 * @author Maria
	 *
	 */
	private class onSendClick implements OnClickListener{
		/**
		 * Gets all the information out of the text fields and gives it to the presenter.
		 */
		public void onClick(View v) {
			String username = ((EditText)findViewById(R.id.lockout_username)).getText().toString();
			String firstname = ((EditText)findViewById(R.id.lockout_firstname)).getText().toString();
			String lastname = ((EditText)findViewById(R.id.lockout_lastname)).getText().toString();
			String email = ((EditText)findViewById(R.id.lockout_email)).getText().toString();
			String phone = ((EditText)findViewById(R.id.lockout_phone)).getText().toString();
			presenter.sendRequest(username,firstname,lastname,email,phone);
			
		}
	}
	
	/**
	 * Displays the inputed string as a popup text.
	 * @param string Message to display.
	 */
	public void displayMessage(String string) {
		Toast toast = Toast.makeText(this, string, Toast.LENGTH_LONG);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();		
	}
	
	/**
	 * Advances app to log in screen.
	 */
	public void advanceToLogin() {
		Intent intent = new Intent(this, LoginActivity.class);
		startActivity(intent);
	}
}
